<?php
/**
 * Controller_Base
 * Класс Controller_Base является базовым для всех контроллеров
 * 
 * @author Sayp
 */
abstract class Controller_Base {
	protected $title;
	protected $keywords;
	protected $description;
	protected $pageHead;
	
	protected $arrRequest;
	
	protected $showLeftColumn = false;
	protected $showRightColumn = false;
	
	protected $arrCss = array(
		'reset.css',
		'plugins/fancybox/jquery.fancybox.css?v=2.1.5',
		'plugins/fancybox/jquery.fancybox-buttons.css',
		'plugins/fancybox/jquery.fancybox-thumbs.css',
		'plugins/flags.css',
		'generic.css',
		'icons.css',
		'carcass.css',
		'search.css',
		'city.css',
		'tour.css',
	);
	
	protected $arrJs = array(
		'plugins/jquery.livequery.min.js',
		'plugins/fancybox/jquery.mousewheel-3.0.6.pack.js',
		'plugins/fancybox/jquery.fancybox.pack.js?v=2.1.5',
		'plugins/fancybox/jquery.fancybox-thumbs.js',
		'plugins/fancybox/jquery.fancybox-buttons.js',
		'plugins/fancybox/jquery.fancybox-media.js',
		'main.js'
	);
	
	protected $bodyClass = '';
	
	public function __construct(array $arrRequest) {
		$this->arrRequest = $arrRequest;
	}
	
	public function addCss($css) {
		$this->arrCss[] = $css;
	}
	
	public function addJs($js) {
		$this->arrJs[] = $js;
	}
	
	/**
	 * Определяем, какой метод запустить
	 */
	abstract public function action();
	
	
	/**
	 * Шапка сайта
	 */
	protected function showHeader() {
		echo '<!DOCTYPE html><!--[if lt IE 7 ]> <html lang="ru" class="ie ie6 ie-pre9"> <![endif]--><!--[if IE 7 ]> <html lang="ru" class="ie ie7 ie-pre9"> <![endif]--><!--[if IE 8 ]> <html lang="ru" class="ie ie8 ie-pre9"> <![endif]--><!--[if IE 9 ]> <html lang="ru" class="ie ie9"> <![endif]--><!--[if (gt IE 9)|!(IE)]><!--> <html lang="ru"> <!--<![endif]-->';
		
		echo '<head>';
			if ($this->title) echo '<title>' . $this->title . '</title>';
			if ($this->keywords) echo '<meta name="keywords" content="' . $this->keywords . '" />';
			if ($this->description) echo '<meta name="description" content="' . $this->description . '" />';
			echo '<meta charset="utf-8" />';
			echo '<meta name="author" content="Sayp" />';
			echo '<link href="/content/images/icons/favicon.ico" rel="shortcut icon" type="image/x-icon" />';
			
			echo '<link rel="stylesheet" type="text/css" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/themes/base/jquery-ui.css" />';
			foreach ($this->arrCss as $css) {
				echo '<link rel="stylesheet" type="text/css" href="http://' . SITE . '/content/css/' . $css . '" />';
			}
			
			echo '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>';
			echo '<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.min.js"></script>';
			
			foreach ($this->arrJs as $js) {
				echo '<script type="text/javascript" src="http://' . SITE . '/content/js/' . $js . '"></script>';
			}
		echo '</head>';
		
		echo '<body' . ($this->bodyClass ? ' class="' . $this->bodyClass . '"' : '') . '>';
		echo '<div id="wrapper">';
		
		$this->showTop();
		echo '<div class="container"><div id="middle">';
		if ($this->pageHead) echo '<h1 class="std-h">' . $this->pageHead . '</h1>';
		if ($this->showLeftColumn) {
			$class = 'with-left';
			$this->showLeft();
		}
		echo '<div id="main"' . (isset($class) ? ' class="' . $class . '"' : null) . '>';
	}
	
	/**
	 * Подвал сайта
	 */
	protected function showFooter() {
		echo '</div>';
		if ($this->showLeftColumn || $this->showRightColumn) echo '<div class="clear"></div>';
		echo '</div></div>'; // middle
		echo '<div id="footer-height"></div>';
		echo '</div>'; // wrapper
		View_Block::showFooter();
		$this->showAnalytics();
		echo '</body>';
		echo '</html>';
	}
	
	protected function showTop() {
		$arrMenus = array();
// 		$arrMenus[] = array('url' => '#', 'text' => 'Туры');
// 		$arrMenus[] = array('url' => '#', 'text' => 'Страны');
// 		$arrMenus[] = array('url' => '#', 'text' => 'Путеводитель');
		
		View_Block::showHeader($arrMenus);
	}
	
	protected function showLeft() {
		View_Block::showLeft();
	}
	
	protected function showRight() {
	}
	
	protected function showAnalytics() {
		if (!SHOW_ANALYTICS) return;
		echo '<!-- Yandex.Metrika counter -->
<script type="text/javascript">
(function (d, w, c) {
    (w[c] = w[c] || []).push(function() {
        try {
            w.yaCounter23924620 = new Ya.Metrika({id:23924620,
                    clickmap:true,
                    trackLinks:true,
                    accurateTrackBounce:true});
        } catch(e) { }
    });

    var n = d.getElementsByTagName("script")[0],
        s = d.createElement("script"),
        f = function () { n.parentNode.insertBefore(s, n); };
    s.type = "text/javascript";
    s.async = true;
    s.src = (d.location.protocol == "https:" ? "https:" : "http:") + "//mc.yandex.ru/metrika/watch.js";

    if (w.opera == "[object Opera]") {
        d.addEventListener("DOMContentLoaded", f, false);
    } else { f(); }
})(document, window, "yandex_metrika_callbacks");
</script>
<noscript><div><img src="//mc.yandex.ru/watch/23924620" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
<!-- /Yandex.Metrika counter -->';
		
		echo "<script type=\"text/javascript\">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-48834893-1']);
  _gaq.push(['_setDomainName', '101tours.ru']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>";
	}
}